package com.hxit.huaxiamelongarden.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hxit.huaxiamelongarden.domin.po.ChatMessage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ChatMessageMapper extends BaseMapper<ChatMessage> {
    // 根据用户 ID 查询与某个用户的聊天记录
    @Select("SELECT * FROM chat_messages WHERE (sender_id = #{userId} AND receiver_id = #{friendId}) OR (sender_id = #{friendId} AND receiver_id = #{userId}) ORDER BY created_at")
    List<ChatMessage> selectMessages(@Param("userId") int userId, @Param("friendId") int friendId);
}
